package IC.lir.instructions;
import IC.lir.operands.Label;
import IC.lir.*;

/**
 * Jump instructions of all kinds:
 * 
 * Jump label
 * JumpTrue label
 * JumpFalse label
 * JumpG label
 * JumpGE label
 * JumpL label
 * Jump LE label
 *
 */
public class JumpInstr extends Instruction {
	private Label 		label;
	public final JumpCondition 	cond;

	/** available jump kinds (conditions) */
	public enum JumpCondition {
		UNCONDITIONAL,
		TRUE,
		FALSE,
		GREATER,
		GREATEREQUAL,
		LESSTHAN,
		LESSTHANEQUAL
	}

	/**
	 * creates a new jump instruction
	 * @param label the label to jump to
	 * @param cond the jump condition
	 */
	public JumpInstr(Label label, JumpCondition cond) {
		this.label = label;
		this.cond = cond;
	}

	/**
	 * creates a new unconditional jump instruction
	 * @param label the label to jump to
	 */
	public JumpInstr(Label label) {
		this.label = label;
		this.cond = JumpCondition.UNCONDITIONAL;
	}

	/**
	 * @return the jump condition
	 */
	public JumpCondition getCond() {
		return cond;
	}

	/**
	 * @return the jump label
	 */
	public Label getLabel() {
		return label;
	}

	@Override
	public <D, U> U accept(Visitor<D, U> v, D context) {
		return v.visit(this, context);
	}
}
